package com.zhuo.project.k3.service.impl;

import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.zhuo.common.utils.SecurityUtils;
import com.zhuo.project.k3.domain.ZzOrganization;
import com.zhuo.project.k3.mapper.ZzOrganizationMapper;
import com.zhuo.project.k3.service.IZzOrganizationService;

/**
 * 卓正组织机构信息Service业务层处理
 * 
 * @author ruoyi
 * @date 2020-03-18
 */
@Service
public class ZzOrganizationServiceImpl implements IZzOrganizationService 
{
    @Autowired
    private ZzOrganizationMapper zzOrganizationMapper;

    /**
     * 查询卓正组织机构信息
     * 
     * @param id 卓正组织机构信息ID
     * @return 卓正组织机构信息
     */
    @Override
    public ZzOrganization selectZzOrganizationById(Long id)
    {
        return zzOrganizationMapper.selectZzOrganizationById(id);
    }

    /**
     * 查询卓正组织机构信息列表
     * 
     * @param zzOrganization 卓正组织机构信息
     * @return 卓正组织机构信息
     */
    @Override
    public List<ZzOrganization> selectZzOrganizationList(ZzOrganization zzOrganization)
    {
        return zzOrganizationMapper.selectZzOrganizationList(zzOrganization);
    }

    /**
     * 新增卓正组织机构信息
     * 
     * @param zzOrganization 卓正组织机构信息
     * @return 结果
     */
    @Override
    public int insertZzOrganization(ZzOrganization zzOrganization)
    {
        ZzOrganization filter = new ZzOrganization();
        filter.setFnumber(zzOrganization.getFnumber());
        List<ZzOrganization> filterList = zzOrganizationMapper.selectZzOrganizationList(filter);
        if(null != filterList && filterList.size()>0){
            Long id = filterList.get(0).getId();
            zzOrganization.setId(id);
            zzOrganization.setUpdateTime(new Date());
            zzOrganization.setUpdateBy(SecurityUtils.getUsername());
            return zzOrganizationMapper.updateZzOrganization(zzOrganization);
        }
        zzOrganization.setCreateBy(SecurityUtils.getUsername());
        zzOrganization.setCreateTime(new Date());
        return zzOrganizationMapper.insertZzOrganization(zzOrganization);
    }

    /**
     * 修改卓正组织机构信息
     * 
     * @param zzOrganization 卓正组织机构信息
     * @return 结果
     */
    @Override
    public int updateZzOrganization(ZzOrganization zzOrganization)
    {
        return zzOrganizationMapper.updateZzOrganization(zzOrganization);
    }

    /**
     * 批量删除卓正组织机构信息
     * 
     * @param ids 需要删除的卓正组织机构信息ID
     * @return 结果
     */
    @Override
    public int deleteZzOrganizationByIds(Long[] ids)
    {
        return zzOrganizationMapper.deleteZzOrganizationByIds(ids);
    }

    /**
     * 删除卓正组织机构信息信息
     * 
     * @param id 卓正组织机构信息ID
     * @return 结果
     */
    @Override
    public int deleteZzOrganizationById(Long id)
    {
        return zzOrganizationMapper.deleteZzOrganizationById(id);
    }
}
